//package java_cup;

/**
 * This class represents a transition in an LALR viable prefix recognition
 * machine. Transition can be under terminals for non-terminals. They are
 * internally linked together into singly linked lists containing AllVns the
 * transitions @out of a single state via the _next field.
 *
 * @see java_cup.LALRState
 * @version last updated: 11/25/95
 * @author Scott Hudson
 *
 */
public class LALRTransition {

    /*-----------------------------------------------------------*/
    /*--- Constructor(s) ----------------------------------------*/
    /*-----------------------------------------------------------*/

    /**
     * Full constructor.
     * 
     * @param on_sym SymbolDraft we are transitioning on.
     * @param to_st  state we transition to.
     * @param next    next transition in linked list.
     */
    public LALRTransition(SymbolDraft on, LALRState to, LALRTransition next) /*throws internal_error*/ {
        /* sanity checks */
        if (on == null)
            throw new InternalError("Attempt to create transition on null SymbolDraft");
        if (to == null)
            throw new InternalError("Attempt to create transition to null state");

        /* initialize */
        _on_symbol = on;
        _to_state = to;
        _next = next;
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /**
     * Constructor with null next.
     * 
     * @param on_sym SymbolDraft we are transitioning on.
     * @param to_st  state we transition to.
     */
    public LALRTransition(SymbolDraft on, LALRState to)
          /*throws internal_error*/
          : this(on, to, null) {
    }

    /*-----------------------------------------------------------*/
    /*--- (Access to) Instance Variables ------------------------*/
    /*-----------------------------------------------------------*/

    /** The SymbolDraft we make the transition on. */
    public SymbolDraft _on_symbol;

    /** The SymbolDraft we make the transition on. */
    public SymbolDraft onSymbol => _on_symbol;

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** The state we transition to. */
    public LALRState _to_state;

    /** The state we transition to. */
    public LALRState toState => _to_state;

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Next transition in linked list of transitions @out of a state */
    public LALRTransition _next;

    /** Next transition in linked list of transitions @out of a state */
    public LALRTransition Next => _next;

    /*-----------------------------------------------------------*/
    /*--- General Methods ---------------------------------------*/
    /*-----------------------------------------------------------*/

    /** Convert to a string. */
    /*@Override*/
    public override string ToString() {
        String result;

        result = "transition on " + onSymbol.Name + " to state [";
        result += _to_state.Index;
        result += "]";

        return result;
    }

    /*-----------------------------------------------------------*/
}
